package com.goodving.guli.bt.lua;

import android.content.Context;

import com.goodving.guli.bt.model.LabFactoryActiveItem;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.model.Keeper;

import org.keplerproject.luajava.LuaState;

import de.greenrobot.gulidao.LuaListDao;


/**
 * Created by john on 2015/12/1.
 */
public class LuaEventMsgs {
    private static LuaEventMsgs __instance;
    private Context context;
    private LuaListDao listDao;

    static {
        __instance = null;
    }

    public LuaEventMsgs() {
        this.listDao = DaoManager.getInstance().getLuaListDao();
        this.context = null;
    }

    public static LuaEventMsgs getInstance(Context context) {
        if (__instance == null) {
            LuaEventMsgs luaEventMsgs = new LuaEventMsgs();
            luaEventMsgs.context = context;
            LuaManager.getInstance(context);
            __instance = luaEventMsgs;
        }
        return __instance;
    }

    public void luaEventAchievementMsg(ConfigDynamicDataInfo configDynamicDataInfo) {
        LuaManager instance = LuaManager.getInstance();
        LuaState luaState = instance.getLuaState();
        luaState.getField(LuaState.LUA_GLOBALSINDEX.intValue(), "getAchievementMsgs");
        luaState.pushJavaObject(this.listDao);
        luaState.pushJavaObject(configDynamicDataInfo);
        luaState.pushJavaObject(Keeper.readPersonInfo());
        instance.callLua(3, 0);
    }

    public void luaEventActivityMsg(ConfigDynamicDataInfo configDynamicDataInfo) {
        LuaManager instance = LuaManager.getInstance();
        LuaState luaState = instance.getLuaState();
        luaState.getField(LuaState.LUA_GLOBALSINDEX.intValue(), "getActivityMsgs");
        luaState.pushJavaObject(this.listDao);
        luaState.pushJavaObject(configDynamicDataInfo);
        luaState.pushJavaObject(Keeper.readPersonInfo());
        instance.callLua(3, 0);
    }

    public void luaEventDefaultMsg(ConfigDynamicDataInfo configDynamicDataInfo) {
        LuaManager instance = LuaManager.getInstance();
        LuaState luaState = instance.getLuaState();
        luaState.getField(LuaState.LUA_GLOBALSINDEX.intValue(), "getDefaultMsgs");
        luaState.pushJavaObject(this.listDao);
        luaState.pushJavaObject(configDynamicDataInfo);
        instance.callLua(2, 0);
    }

    public void luaEventSleepMsg(ConfigDynamicDataInfo configDynamicDataInfo) {
        LuaManager instance = LuaManager.getInstance();
        LuaState luaState = instance.getLuaState();
        luaState.getField(LuaState.LUA_GLOBALSINDEX.intValue(), "getSleepMsgs");
        luaState.pushJavaObject(this.listDao);
        luaState.pushJavaObject(configDynamicDataInfo);
        instance.callLua(2, 0);
    }

    public void luaEventSysInfoMsg(ConfigDynamicDataInfo configDynamicDataInfo) {
        LuaManager instance = LuaManager.getInstance();
        LuaState luaState = instance.getLuaState();
        luaState.getField(LuaState.LUA_GLOBALSINDEX.intValue(), "getSysInfoMsgs");
        luaState.pushJavaObject(this.listDao);
        luaState.pushJavaObject(configDynamicDataInfo);
        instance.callLua(2, 0);
        GuliLog.tracePrintInfo("SCORPIONEAL", "call luaEventSysInfoMsg " + configDynamicDataInfo.toString());
    }

    public void luaLabFactoryActivityMsg(LabFactoryActiveItem labFactoryActiveItem) {
        LuaManager instance = LuaManager.getInstance();
        LuaState luaState = instance.getLuaState();
        luaState.getField(LuaState.LUA_GLOBALSINDEX.intValue(), "getLabFactoryActivityMsgs");
        luaState.pushJavaObject(this.listDao);
        luaState.pushJavaObject(labFactoryActiveItem);
        instance.callLua(2, 0);
    }

    public void testLuaImp(int i, ConfigDynamicDataInfo configDynamicDataInfo) {
        LuaManager instance = LuaManager.getInstance();
        LuaState luaState = instance.getLuaState();
        luaState.getField(LuaState.LUA_GLOBALSINDEX.intValue(), "getEventMsgs");
        luaState.pushJavaObject(this.listDao);
        luaState.pushJavaObject(configDynamicDataInfo);
        luaState.pushInteger(i);
        instance.callLua(3, 0);
    }
}
